﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Habi.Solver.Helpers
{
    public class RegexHelper
    {
        public static string Match(string input, string pattern)
        {
            if (string.IsNullOrEmpty(input)) return string.Empty;

            Regex regex = new Regex(pattern);
            var match = regex.Match(input);
            if (!match.Success) return string.Empty;

            return match.Value;
        }

        public static string MatchRegUninstallPath(string input)
        {
            if (string.IsNullOrEmpty(input)) return string.Empty;
            if (input.IndexOf('\"') == 0)
            {
                return Match(input, "\"(.*?)\"").Replace("\"","");
            }
            else
            {
                return Match(input, @"[a-zA-Z]:(\\[\w\u4e00-\u9fa5\(\)\[\]\{\}`~!@#$%^&]+[`~!@#$%^&\(\)\[\]\{\}\s\w\u4e00-\u9fa5]+)+(\\[`~!@#$%^&\w\u4e00-\u9fa5.\(\)\[\]\{\}]([.]*[`~!@#$%^&\w\s\(\)\[\]\{\}\u4e00-\u9fa5])+)+");
            }
        }
    }
}
